<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:if test="${type=='IN'}"><c:set var="pageTitle" value="收件箱" /></c:if><c:if test="${type=='OUT'}"><c:set var="pageTitle" value="发件箱" /></c:if>
<%@ include file="../inc/Title.jsp"%>
<head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<link href="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css" rel="stylesheet" type="text/css">
<script src="/js/QueryList.js"></script>
<script src="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js"></script>
<script language="javascript">
	function doNew(repId){
		window.location="/message/MessageNew.ihtm?reply_id="+repId;
	}
	function doShow(id){
		window.location="/message/MessageInfo.ihtm?id="+id;
	}
	function doDelete(id){
		parent.ShowConfirm('确认框','确定删除吗？',340,80,"doDelMsg('"+id+"','${type}')");//doDelMsg是父窗口的
	}
	function refreshWin(){//父窗口的doDelMsgCallBack调用
		window.location.reload(true);
	}
	function doGo(pageIndex){
		var str=getSearchCondition()+"&current_page="+pageIndex;
		window.location="/message/MessageList.ihtm?"+str;
	}
	function doJump(pageIndex){
		if(window.event.keyCode==13){
			doGo(pageIndex);
		}
	}
	function doInit(){
		var type="${type}";
		parent.openNode(type);
		/**
		if(type=="IN"){
			if(window.parent.opener.checkNewMessage!=null){//从菜单栏打开的
				window.parent.opener.checkNewMessage();
			}else{//从桌面打开的
				window.parent.opener.parent.frames["topFrame"].checkNewMessage();
			}
		}
		**/
		document.getElementById("ttl").focus();
	}
	function selectStafferName(objId,checkObjId){
		var url="/base/StafferMainForSelect.ihtm";
		var cb="selectStafferNameCallBack('"+objId+"','"+checkObjId+"')";//selectStafferNameCallBack是父窗口的
		parent.ShowIframe("选择员工",url,800,500,cb);
	}
	function selectStafferNameAct(objId,checkObjId,ret){//父窗口的selectStafferNameCallBack调用
		var arr=ret.split(";");
		document.getElementById(objId).value=arr[1];
		doAutoCheck(checkObjId);
	}
	function checkDateStr(){
		var startDate=document.getElementById("start_date").value;
		if(startDate==null || startDate==''){
			parent.ShowAlert('提示框','请选择开始日期',200,100);
			return false;
		}else{
			var arr=startDate.split("-");
			if(arr.length==null || arr.length!=3){
				parent.ShowAlert('提示框','开始日期格式不正确',200,100);
				return false;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				parent.ShowAlert('提示框','开始日期格式不正确',200,100);
				return false;
			}
		}
		var endDate=document.getElementById("end_date").value;
		if(endDate==null || endDate==''){
			parent.ShowAlert('提示框','请选择结束日期',200,100);
			return false;
		}else{
			var arr=endDate.split("-");
			if(arr.length==null || arr.length!=3){
				parent.ShowAlert('提示框','结束日期格式不正确',200,100);
				return false;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				parent.ShowAlert('提示框','结束日期格式不正确',200,100);
				return false;
			}
		}
		return true;
	}
	function createPageParaStr(){
		var str="start_date="+encodeURIComponent(document.getElementById("start_date").value);
		str=str+"&end_date="+encodeURIComponent(document.getElementById("end_date").value);
		
		<c:if test="${type=='IN'}">str=str+"&sen="+encodeURIComponent(document.getElementById("sen").value);</c:if>
		str=str+"&ttl="+encodeURIComponent(document.getElementById("ttl").value);
		str=str+"&con="+encodeURIComponent(document.getElementById("con").value);
		
		return str;
	}
	function createProgramParaStr(){
		var str="start_date="+encodeURIComponent(document.getElementById("hid_start_date").value);
		str=str+"&end_date="+encodeURIComponent(document.getElementById("hid_end_date").value);
		<c:if test="${type=='IN'}">str=str+"&sen="+encodeURIComponent(document.getElementById("hid_sen").value);</c:if>
		str=str+"&ttl="+encodeURIComponent(document.getElementById("hid_ttl").value);
		str=str+"&con="+encodeURIComponent(document.getElementById("hid_con").value);
		return str;
	}
	function doSearch(){
		var str="type=${type}";
		if(IsAdvSearch){//高级
			str=str+"&search_type=1";
			if(document.getElementById("cb_ttl").checked){
				var ttl=document.getElementById("ttl").value.trim();
				if(ttl==null || ttl==""){
					parent.ShowAlert('提示框','请输入主题',200,100);
					return;
				}
				str=str+"&cb_ttl=1";
			}
			if(document.getElementById("cb_con").checked){
				var con=document.getElementById("con").value.trim();
				if(con==null || con==""){
					parent.ShowAlert('提示框','请输入内容',200,100);
					return;
				}
				str=str+"&cb_con=1";
			}
			<c:if test="${type=='IN'}">
			if(document.getElementById("cb_sen").checked){
				var sen=document.getElementById("sen").value.trim();
				if(sen==null || sen==""){
					parent.ShowAlert('提示框','请输入发送人',200,100);
					return;
				}
				str=str+"&cb_sen=1";
			}
			</c:if>
			if(document.getElementById("cb_sen_date").checked){
				if(checkDateStr()){
					str=str+"&cb_sen_date=1";
				}else{
					return;
				}
			}
		}else{//快速
			str=str+"&search_type=2";
			var ttl=document.getElementById("ttl").value.trim();
			if(ttl==null || ttl==""){
				parent.ShowAlert('提示框','请输入主题',200,100);
				return;
			}
		}
		var paraStr=createPageParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		window.location="/message/MessageList.ihtm?"+str;
	}
	function getSearchCondition(){
		var searchType="${searchType}";
		var str="type=${type}&relation_id=${relationId}&search_type="+searchType;
		if(searchType=="1"){//高级
			<c:if test="${cbSenDate=='1'}">str=str+"&cb_sen_date=1";</c:if>
			<c:if test="${cbTtl=='1'}">str=str+"&cb_ttl=1";</c:if>
			<c:if test="${cbCon=='1'}">str=str+"&cb_con=1";</c:if>
			<c:if test="${cbSen=='1'}">str=str+"&cb_sen=1";</c:if>
		}else{//快速
			
		}
		var paraStr=createProgramParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		return str;
	}
	function checkInput(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function doAutoCheck(objId){
		if(document.getElementById(objId).style.visibility!="hidden"){
			document.getElementById(objId).checked=true;
		}
	}
	function getMultiId(){
		var ob_arr = document.getElementsByName("query_checkbox");
		var str="";
		for (i=0;i<ob_arr.length;i++){
			if ((ob_arr[i].checked == true)){
				if(str!=""){
					str=str+";";
				}
				str = str+ob_arr[i].value;
			}
		}
		return str;
	}
	function doMultiDelete(){
		var str=getMultiId();
		if(str==""){
			parent.ShowAlert('提示框','请选择要删除的消息!',200,100);
		}else{
			doDelete(str);
		}
	}
	function doFlag(){
		var str=getMultiId();
		if(str==""){
			parent.ShowAlert('提示框','请选择要标记的消息!',200,100);
		}else{
			parent.ShowConfirm('确认框','确定将选中的消息标记为已读吗？',340,80,"doReadFlag('"+str+"')");//doReadFlag是父窗口的
		}
	}
	<c:if test="${enterpriseInfo.msgInterval>0}">
		setTimeout("refreshWin()",1000*60*${enterpriseInfo.msgInterval});
	</c:if>
	<c:if test="${enterpriseInfo.msgInterval<=0}">
		setTimeout("refreshWin()",1000*60*1);
	</c:if>
</script>
</head>
<body oncontextmenu="return false" onLoad="doInit();" scroll="no" style="background: #EAFAFF;">
		<div id="scrollDiv" style="OVERFLOW:auto;height:468px;">
		  <div class="main search-business">
			   <div class="cue-info">
					<h4>
						<c:if test="${type=='IN'}">收件箱</c:if><c:if test="${type=='OUT'}">已发送消息</c:if>
					</h4>				   	
			  </div>
			  
			<div class="MsgContent">
				<!-- 筛选控件栏 -->
		        <div class="FilterBar ClearFix">
		            <div class="SearchIcon"></div>
		            <span class="fl">
		            	<table class="MoreOption" cellpadding="0" cellspacing="0">
		            		<th class="c1" width="60px">
		            			<input type="checkbox" name="cb_ttl" id="cb_ttl" <c:if test="${cbTtl=='1' || searchType=='2'}">checked="true"</c:if> style="visibility:hidden;" />
		            			主题
		            		</th>
		            		<td class="c3" width="140px">
		            			<input type="text" class="TextBox" maxlength="15" name="ttl" id="ttl" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_ttl');" value="<c:out value="${ttl}" />" >
								<input type="hidden" id="hid_ttl" value="<c:out value="${ttl}" />">
		            		</td>
		            	</table>
		            </span>
		            <span class="fr">
		            	<a href="javascript:;" id="lnkMoreOption">更多查询选项</a>
			  			<input type="button" value=" 查 询" onClick="doSearch();" id="sSearchButton" name="sSearchButton" class="buttom search-but">
			  			<c:if test="${type=='IN'}"><input value=" 标为已读" id="sFlagButton" name="sFlaghButton" type="button" class="buttom search-audit" onclick="javascript:doFlag();" /></c:if>
						<input id="sDelButton" name="sDelButton" value=" 删 除" type="button" class="buttom search-remo" onclick="javascript:doMultiDelete();" />
						<input type="button" value=" 发消息" id="sNewButton" name="sNewButton" class="buttom search-add" onclick="javascript:doNew('');" />
		            </span>
					<div id="dvMoreOptionBox" class="MoreOptionBox" style="display:none;">
						<table class="MoreOption" cellpadding="0" cellspacing="0">
							<tr>
								<th class="c1" width="60px">
				        			<input type="checkbox" name="cb_con" id="cb_con" <c:if test="${cbCon=='1'}">checked="true"</c:if>>
				        			内容
				        		</th>
				        		<td class="c3" width="220px">
				        			<input type="text" class="TextBox" maxlength="15" name="con" id="con" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_con');" value="<c:out value="${con}" />" >
									<input type="hidden" id="hid_con" value="<c:out value="${con}" />">
				    			</td>
				    		</tr>
				    		<c:if test="${type=='IN'}">
				    		<tr>
								<th class="c1">
				        			<input type="checkbox" name="cb_sen" id="cb_sen" <c:if test="${cbSen=='1'}">checked="true"</c:if>>
				        			发送人
				        		</th>
				        		<td class="c3">
				        			<input type="text" class="TextBox" maxlength="15" name="sen" id="sen" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_sen');" value="<c:out value="${sen}" />" >
									<img class="imgIconButton" src="/images/make-a.gif" onClick="selectStafferName('sen','cb_sen');" style="cursor:pointer;" />
									<input type="hidden" id="hid_sen" value="<c:out value="${sen}" />">
				    			</td>
				    		</tr>
				    		</c:if>
				    		<tr>
								<th class="c1">
				        			<input type="checkbox" name="cb_sen_date" id="cb_sen_date" <c:if test="${cbSenDate=='1'}">checked="true"</c:if>>
				        			日期
				        		</th>
				        		<td>
				        			<input type="text" class="TextBox Datetime" maxlength="15" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_sen_date');" id="start_date" name="start_date" value="<c:out value="${startDate}" />" >
									<img src="/images/calendar.gif" class="imgIconButton" onClick="displayCalendar(document.getElementById('start_date'),'yyyy-mm-dd',this,false,'doAutoCheck(\'cb_sen_date\')');">
									<input type="hidden" id="hid_start_date" value="<c:out value="${startDate}" />">
						            至
									<input type="text" class="TextBox Datetime" maxlength="15" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_sen_date');" id="end_date" name="end_date" value="<c:out value="${endDate}" />" >
									<img src="/images/calendar.gif" class="imgIconButton" onClick="displayCalendar(document.getElementById('end_date'),'yyyy-mm-dd',this,false,'doAutoCheck(\'cb_sen_date\')');">
									<input type="hidden" id="hid_end_date" value="<c:out value="${endDate}" />">
				    			</td>
				    		</tr>
				    	</table>
				    	
						<div class="OptionOrderBy">
		                    <span class="fr"><a href="javascript:;" id="lnkHiddenOption">隐藏查询选项</a></span>
		                </div>
					</div>
				</div>
			</div>
			
			<!-- 提示信息显示栏 -->
	        <div class="MsgBar">
	            <%@include file="../inc/AlertMsg.jsp"%>
	        </div>
			
			  <div class="table-list" style="width:98%; padding:15px 0 15px 10px; float:left;">
				  <table width="100%">
				      <tr>
				      	<th width="14"><input type="checkbox" onClick="javascript:checkall(this);"></th>
				        <th width="60%">主题</th>
				        <th width="10%">
							<c:if test="${type=='IN'}">发送人</c:if>
							<c:if test="${type=='OUT'}">接收人</c:if>
						  </th>
				        <th width="17%">时间</th>
				        <th width="13%">操作</th>
				      </tr>
					  <c:forEach var="item" items="${qr.list}" varStatus="i">
						<c:if test="${type=='IN'}">
							<c:set var="itemId" value="${item[0].id}" />
							<c:set var="itemTitle" value="${item[0].title}" />
							<c:set var="itemName" value="${item[0].senderName}" />
							<c:set var="senderId" value="${item[0].senderId}" />
							<c:set var="itemTime" value="${item[0].sendTime}" />
							<c:set var="hasAttach" value="${item[0].hasAttach}" />
							<c:set var="receiverRead" value="${item[1].receiverRead}" />
						</c:if>
						<c:if test="${type=='OUT'}">
							<c:set var="itemId" value="${item.id}" />
							<c:set var="itemTitle" value="${item.title}" />
							<c:set var="itemName" value="${item.receiverName}" />
							<c:set var="itemTime" value="${item.sendTime}" />
							<c:set var="hasAttach" value="${item.hasAttach}" />
							<c:set var="receiverRead" value="" />
						</c:if>
						<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
						<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
				      <tr class="${trClass}" index="${i.index+1}" style='cursor:pointer;' ondblclick='javascript:DoubleClick(this)' onClick='javascript:ClickCheck(this,true)' onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
				      	<td><input type="checkbox" onClick="javascript:ClickCheck(this,true);" name='query_checkbox' value="${itemId}"></td>
				        <td style="text-align:center;">
							<a href="javascript:doShow(${itemId});">${itemTitle}</a>
							<c:if test="${hasAttach=='Y'}"><img src="/images/a32.gif" border="0"></c:if>
							<c:if test="${receiverRead=='N'}"><img src="/images/new.gif"></c:if>
						</td>
				        <td>${itemName}</td>
				        <td><fmt:formatDate value="${itemTime}" pattern="yyyy-MM-dd HH:mm"/></td>
				        <td>
							<c:if test="${type=='IN' && senderId!=0}"><a href="javascript:doNew('${itemId}');">回复</a></c:if>
							<a href="javascript:doDelete('${itemId}');">删除</a>
						</td>
				      </tr>
					  </c:forEach>
		        </table>
		       <%@include file="../inc/Pages.jsp"%>     
			   </div>
	</div>
 </div>
</body>
</html>
<script type="text/javascript">
	var IsAdvSearch = false;
	(function(){
		doInit();
	    
	    var lnkMoreOption   = document.getElementById('lnkMoreOption');
	    var lnkHiddenOption = document.getElementById('lnkHiddenOption');
	    lnkMoreOption.onclick = function(){
	    	IsAdvSearch = true;
	        document.getElementById('dvMoreOptionBox').style.display = 'block';
	        document.getElementById('cb_ttl').style.visibility = 'visible';
	        this.style.visibility = 'hidden';
	    };
	    lnkHiddenOption.onclick = function(){
	    	IsAdvSearch = false;
	        document.getElementById('dvMoreOptionBox').style.display = 'none';
	        document.getElementById('cb_ttl').style.visibility = 'hidden';
	        lnkMoreOption.style.visibility = 'visible';
	    };
	})();
</script>